<template>
  <div>
    <h1>房源列表</h1>
    <!--房源信息查询-->
    <el-form :inline="true" :model="formInline" class="demo-form-inline">
      <el-form-item label="出租状态">
        <el-select v-model="formInline.status" placeholder="请选择出租状态">
          <el-option label="待出租" value="0" />
          <el-option label="已出租" value="1" />
        </el-select>
      </el-form-item>

      <el-form-item label="发布状态">
        <el-select v-model="formInline.publishStatus" placeholder="请选择发布状态">
          <el-option label="未发布" value="0" />
          <el-option label="已发布" value="1" />
        </el-select>
      </el-form-item>

      <el-form-item label="楼盘名称">
        <el-input v-model="formInline.name" placeholder="请输入楼盘名称" />
      </el-form-item>

      <el-form-item label="房源名称">
        <el-input v-model="formInline.roomName" placeholder="请输入房源名称" />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="RoomList()">查询</el-button>
        <el-button type="primary" @click="resetForm()">清空</el-button>
      </el-form-item>
    </el-form>

    <!-- 按钮      -->
    <el-button type="warning" @click="handleEdit(0)">推荐房源</el-button>
    <el-button type="warning" @click="handleEdit(1)">取消推荐</el-button>
    <!--列表展示-->
    <el-table
      ref="multipleTable"
      :data="tableData"
      tooltip-effect="dark"
      style="width: 100%"
      @selection-change="handleSelectionChange"
    >
      <el-table-column
        type="selection"
        width="55"
      />
      <el-table-column
        prop="id"
        label="ID"
        width="200"
      />
      <el-table-column
        prop="frontCover"
        label="房源图片"
        width="100"
      >
        <template slot-scope="scope">
          <el-avatar shape="square" :size="50" :src="scope.row.frontCover" />
        </template>
      </el-table-column>
      <el-table-column
        prop="roomName"
        label="房源名称"
        width="180"
      />
      <el-table-column
        prop="name"
        label="楼盘名称"
        width="180"
      />
      <el-table-column
        prop="roomCode"
        label="房源编号"
        width="100"
      />
      <el-table-column
        prop="proportion"
        label="面积"
        width="100"
      />
      <el-table-column
        prop="rental"
        label="租金"
        width="100"
      />
      <el-table-column
        label="出租状态"
        width="120"
      >
        <template slot-scope="scope">
          {{ scope.row.status==0?'待出租':'已出租' }}
        </template>
      </el-table-column>
      <el-table-column
        prop="username"
        label="发布人"
        width="120"
      />
      <el-table-column
        label="发布状态"
        width="120"
      >
        <template slot-scope="scope">
          {{ scope.row.publishStatus==0?'已发布':'未发布' }}
        </template>
      </el-table-column>
      <el-table-column
        label="是否推荐"
        width="120"
      >
        <template slot-scope="scope">
          {{ scope.row.recommended==1?'已推荐':'未推荐' }}
        </template>
      </el-table-column>
    </el-table>
    <!--分页展示-->
    <el-pagination
      background
      :current-page="pageNum"
      :page-sizes="[5, 10, 15, 20]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />

  </div>
</template>

<script>
export default {
  name: 'Room',
  data() {
    return {
      // 列表
      tableData: [],
      // 分页
      pageNum: 1,
      pageSize: 5,
      total: 0,
      // 查询
      formInline: {},
      multipleSelection: []

    }
  },
  created() {
    this.RoomList()
  },
  methods: {
    handleSelectionChange(val) {
      this.multipleSelection = val.map(row => row.id).join(',')
      /* if (this.multipleSelection!=null){
        var id = this.multipleSelection.map(row=>row.id).join(",")
      }*/
      console.log(this.multipleSelection)
    },
    handleEdit(value) {
      if (value) {
        this.axios.get('http://localhost:9999/house-resource/tbRoomInfo/recommendedRooms', {
          params: {
            recommendeds: this.multipleSelection
          }
        }).then((response) => {
          // console.log(response.data)
          alert(response.data.msg)
          this.RoomList()
        })
      } else {
        this.axios.get('http://localhost:9999/house-resource/tbRoomInfo/qxRecommendedRooms', {
          params: {
            recommendeds: this.multipleSelection
          }
        }).then((response) => {
          // console.log(response.data)
          alert(response.data.msg)
          this.RoomList()
        })
      }
    },
    // 列表
    RoomList() {
      this.axios.get('http://localhost:9999/house-resource/tbRoomInfo/list', {
        params: {
          pageNum: this.pageNum,
          pageSize: this.pageSize,
          status: this.formInline.status,
          publishStatus: this.formInline.publishStatus,
          name: this.formInline.name,
          roomName: this.formInline.roomName
        }
      }).then((response) => {
        console.log(response.data)
        this.tableData = response.data.obj.list
        this.total = response.data.obj.total
      })
    },
    // 分页
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`)
      this.pageSize = val
      this.RoomList()
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`)
      this.pageNum = val
      this.RoomList()
    },
    // 清空
    resetForm() {
      this.formInline = {}
    }
  }

}
</script>

